package our;

import com.maxmind.geoip.Location;

import com.maxmind.geoip.LookupService;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
	
	



  public static void main(String args[]) throws Exception {

	Scanner s1 = new Scanner(new File("serwery1.txt"));
	ArrayList<String> list1 = new ArrayList<String>();
	while (s1.hasNext()){
		    list1.add(s1.next());
	}
	s1.close();
	
	Scanner s2 = new Scanner(new File("serwery2.txt"));
	ArrayList<String> list2 = new ArrayList<String>();
	while (s2.hasNext()){
		    list2.add(s2.next());
	}
	s2.close();
	
	File odleglosci = new File("odleglosci.txt");
	BufferedWriter writer = new BufferedWriter(new FileWriter(odleglosci));
	
	for(int x=0; x<list1.size(); x++){
	LookupService lookupService = new LookupService("GeoLiteCity.dat");

	Location locationFirst = lookupService.getLocation(list1.get(x));
    Location locationSecond = lookupService.getLocation(list2.get(x));
    
    double lat1, lat2, long1, long2;
    lat1 = locationFirst.latitude;
    lat2 = locationSecond.latitude;
    long1 = locationFirst.longitude;
    long2 = locationSecond.longitude;    
    lat1 = Math.round(lat1*100.0)/100.0;
    lat2 = Math.round(lat2*100.0)/100.0;
    long1 = Math.round(long1*100.0)/100.0;
    long2 = Math.round(long2*100.0)/100.0;
    double dist = locationFirst.distance(locationSecond);
    dist = Math.round(dist*100.0)/100.0;
    
			writer.write("Distance between \t" + locationFirst.countryName
					+ "\t" + lat1 + "\t" + long1 + "\t" + list1.get(x)
					+ "\t and \t" + locationSecond.countryName + "\t" + lat2
					+ "\t" + long2 + "\t"  + list2.get(x)
					+ ": \t" + dist + "\t kilometers");
			writer.newLine();
    };
	writer.close();
  }

}